﻿namespace Reap.AzureResource.Service
{
	using System.Collections.Generic;

	using Reap.AzureResource.Data.Infrastructure;
	using Reap.AzureResource.Data.Repositories;
	using Reap.AzureResource.Model.Models;
	using Reap.Common.Runtime.Dependency;

	[Dependency(typeof(IResourceActivityService),ComponentLifeStyle.InRequestScope,Key = "IResourceActivityService")]
	public class ResourceActivityService : IResourceActivityService
	{
		#region Fields

		private readonly IResourceActivityRepository repository;

		private readonly IUnitOfWork unitOfWork;

		#endregion

		#region Constructors and Destructors

		public ResourceActivityService(IUnitOfWork unitOfWork, IResourceActivityRepository repository)
		{
			this.unitOfWork = unitOfWork;
			this.repository = repository;
		}

		#endregion

		#region Public Methods and Operators

		public ResourceActivity AddResouceActivity(ResourceActivity addResouceActivity)
		{
			this.repository.Add(addResouceActivity);
			this.SaveChanges();
			return addResouceActivity;
		}

		public IEnumerable<ResourceActivity> GetActivitiesByResourceId(int resourceId)
		{
			IEnumerable<ResourceActivity> activities = this.repository.GetMany(act => act.ResourceId == resourceId);
			return activities;
		}

		public void SaveChanges()
		{
			this.unitOfWork.SaveChanges();
		}

		#endregion
	}

	public interface IResourceActivityService
	{
		#region Public Methods and Operators

		ResourceActivity AddResouceActivity(ResourceActivity addResouceActivity);

		IEnumerable<ResourceActivity> GetActivitiesByResourceId(int resourceId);

		#endregion
	}
}